package com.favccxx.message.application;

import com.favccxx.message.domain.message.entity.endpoint.MessageEndPointRepo;
import com.favccxx.message.domain.message.entity.process.MessageProcessRule;
import com.favccxx.message.domain.message.entity.router.MessageRouter;
import com.favccxx.message.domain.message.entity.router.MessageRouterRepo;
import com.favccxx.message.domain.message.entity.endpoint.RabbitmqEndPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class MessageAppService {

    @Autowired
    MessageEndPointRepo messageEndPointRepo;
    @Autowired
    MessageRouterRepo messageRouterRepo;


    public void saveRabbitMQ(RabbitmqEndPoint rabbitmqEndPoint) {
        messageEndPointRepo.save(rabbitmqEndPoint);
    }

    public void saveMessageRouter(MessageRouter messageRouter) {
        messageRouterRepo.save(messageRouter);
    }


    /**
     * 根据Id查找消息路由
     *
     * @param id
     * @return
     */
    public MessageRouter findById(String id) {
        Optional<MessageRouter> opt = messageRouterRepo.findById(id);
        if (opt.isPresent()) {
            return opt.get();
        }
        return null;
    }


}
